home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / Gui4Cli / Dir / Dir.calc < prev    next >
Encoding:
Text File  |  1980-01-03  |  6.9 KB  |  289 lines

  1. G4C
  2.  
  3. ; dir.calc
  4.  
  5. ; A calculator, which uses ARexx to calculate & display the results.
  6. ; NOTE : ** means "to the power of"  i.e. 5**2 = 25
  7.  
  8. ; Other ARexx operators can be entered manually if needed.
  9.  
  10.  
  11. WINBIG   400 24 160 128 "RexxCalc"   ; Our window.
  12. WinType  11110001                ; It has all standard gadgets & bottom resize
  13. WINBACKGROUND PATTERN 0 2        ; Add a flashy background..
  14. varpath ''             ; use only private variables
  15.  
  16.  
  17. BOX  0 0 0 0 IN ICONDROP ; A window sized box, taking us way beyond mere "cool"
  18.  
  19. ;************************** GENERAL EVENTS ***********************************
  20.  
  21. xONLOAD                     ; Upon loading of the GUI
  22. setscreen dir.calc $*SCREEN
  23. ifexists port AREXX                      ; check if rexx mast is running
  24. or $*REXXOK = 1
  25.    ; it's running
  26. else
  27.    guiload :rexxcheck.g
  28.    if $*REXXOK != 1              ; quit if rexxcheck failed
  29.        stop
  30.    endif
  31. endif
  32. calc.var = ""               ; This is our main variable
  33. setgad dir.calc 2 HIDE      ; hide the ticker tape
  34. GUIOPEN dir.calc
  35. setvar mem  .mem1           ; These are the Memory variables
  36. setvar .mem1 0              ;     The ones starting with a full stop,
  37. setvar .mem2 0              ;     are env: variables
  38. setvar .mem3 0
  39. setvar .mem4 0
  40. setvar .mem5 0
  41. setvar membuff ""
  42. setvar .result "0"          ; somewhere to put the result (env: variable)
  43. setvar calcmode SMALL       ; small/big window
  44.  
  45. xonclose
  46. guiquit dir.calc
  47.  
  48. xOnQuit                     ; On quitting we delete the env variables, 
  49. delete env:.mem#?           ; so they don't linger in Env:
  50. delvar .result
  51.  
  52. ;***************************** BUTTONS GALORE ! ******************************
  53. ; All these buttons do the same thing. They AppVar their number or letter
  54. ; to our main variable and redisplay it
  55.  
  56.  
  57. ;=======================> The Buttons for the plain numbers
  58.  
  59. xBUTTON 10 25 25 15 1
  60. gadkey 1                       ; Keyboard shortcut
  61. AppVar calc.var 1              ; AppVar the number to "calc.var"
  62. update dir.calc  1 $calc.var   ; and re-display it.
  63.  
  64. xBUTTON 36 25 25 15 2          ; same as above
  65. gadkey  2
  66. AppVar calc.var 2
  67. update dir.calc  1 $calc.var
  68.  
  69. xBUTTON 62 25 25 15 3
  70. gadkey  3
  71. AppVar calc.var 3
  72. update dir.calc  1 $calc.var
  73.  
  74. xBUTTON 10 41 25 15 4
  75. gadkey  4
  76. AppVar calc.var 4
  77. update dir.calc  1 $calc.var
  78.  
  79. xBUTTON 36 41 25 15 5
  80. gadkey  5
  81. AppVar calc.var 5
  82. update dir.calc  1 $calc.var
  83.  
  84. xBUTTON 62 41 25 15 6
  85. gadkey  6
  86. AppVar calc.var 6
  87. update dir.calc  1 $calc.var
  88.  
  89. xBUTTON 10 57 25 15 7
  90. gadkey  7
  91. AppVar calc.var 7
  92. update dir.calc  1 $calc.var
  93.  
  94. xBUTTON 36 57 25 15 8
  95. gadkey  8
  96. AppVar calc.var 8
  97. update dir.calc  1 $calc.var
  98.  
  99. xBUTTON 62 57 25 15 9
  100. gadkey  9
  101. AppVar calc.var 9
  102. update dir.calc  1 $calc.var
  103.  
  104. xBUTTON 10 73 25 15 0
  105. gadkey  0
  106. AppVar calc.var 0
  107. update dir.calc  1 $calc.var
  108.  
  109. xBUTTON 36 73 25 15 .
  110. gadkey  .
  111. AppVar calc.var .
  112. update dir.calc  1 $calc.var
  113.  
  114. xBUTTON 62 73 25 15 <        ; backspace
  115. gadkey #8
  116. cutvar calc.var CUT CHAR -1 ""   ; It will delete the last character of
  117. update dir.calc  1 $calc.var     ; "calc.var" and re-display it
  118.  
  119. ;=========================> The operators
  120.  
  121. xBUTTON 90 25 25 15 /
  122. gadkey  /
  123. AppVar calc.var /
  124. update dir.calc  1 $calc.var
  125.  
  126. xBUTTON 90 41 25 15 *       ; hit twice for square
  127. gadkey  *
  128. AppVar calc.var *
  129. update dir.calc  1 $calc.var
  130.  
  131. xBUTTON 90 57 25 15 -
  132. gadkey  -
  133. AppVar calc.var -
  134. update dir.calc  1 $calc.var
  135.  
  136. xBUTTON 90 73 25 15 +
  137. gadkey  +
  138. AppVar calc.var +
  139. update dir.calc  1 $calc.var
  140.  
  141. ;------------- right most bank
  142.  
  143. xBUTTON 116 25 35 15 (
  144. gadkey  (
  145. AppVar calc.var (
  146. update dir.calc  1 $calc.var
  147.  
  148. xBUTTON 116 41 35 15 )
  149. gadkey  )
  150. AppVar calc.var )
  151. update dir.calc  1 $calc.var
  152.  
  153. xBUTTON 116 57 35 15 CLR       ; Clear
  154. gadkey #127
  155. update dir.calc  1 0
  156. setvar calc.var ""
  157. if $calcmode = BIG                ; update ticker tape
  158.    lvuse dir.calc 2
  159.    LVAdd '** Clear **'
  160. endif
  161.  
  162. xBUTTON 116 73 35 15 =
  163. gadkey #13
  164. gosub dir.calc calculate        ; GoSub the routine which does the calculation
  165.  
  166.  
  167. ;===========================> This is our display panel. - Note it's
  168. ; a xTEXTin type gadget, so we can enter a calculation directly into it.
  169.  
  170. xTEXTIN 10 5 140 18 "" calc.var 0 512
  171. GADID 1
  172. gosub dir.calc calculate        ; GoSub the routine which does the calculation
  173.  
  174.  
  175. ;===================> routine to calculate & display result
  176.  
  177. xROUTINE calculate
  178. lvuse dir.calc 2                        ; use ticker tape lv
  179. if $calc.var > ""                          ; If there is an entry
  180.    if $calcmode = BIG
  181.       LVAdd '$calc.var'
  182.    endif
  183.    cli "rx 'say >env:.result $calc.var'"
  184.    update dir.calc  1  $.result       ; and display the answer EVAL returned
  185.    setvar calc.var $.result           ; We set "calc.var" to the result
  186.    if $calcmode = BIG                 ; update ticker tape
  187.       LVAdd '=> $calc.var'
  188.    endif
  189.    if $calc.var = 0 
  190.       calc.var = ""                   ; and if it's 0, we empty it (looks nicer)
  191.    endif
  192. endif 
  193.  
  194.  
  195. ;***************************** MEMORIES **************************************
  196.  
  197. ; If you look at the following code carefully, you will see that we
  198. ; need a variable within a variable. 
  199. ; We use "membuff" to construct such a variable.
  200.  
  201. ;=======================> Memories display panel
  202.  
  203. xTEXTIN 10 90 140 16 "" $mem 0 30
  204. GadID 5
  205.  
  206. ;=======================> Memories cycler
  207.  
  208. xCycler 10 108 60 15 "" mem
  209. Cstr "M1" .mem1
  210. Cstr "M2" .mem2
  211. Cstr "M3" .mem3
  212. Cstr "M4" .mem4
  213. Cstr "M5" .mem5
  214. setvar membuff "\$$mem"    ; This means set membuff to $ + whatever is in "mem"
  215. update dir.calc 5 $membuff  ; so that it points to the correct variable
  216.  
  217. ;=======================> Memory IN/OUT
  218.  
  219. xButton 70 108 20 15 I          ; These buttons do the usual MEM in/out/+/-
  220. SetVar $mem $calc.var           ; stuff that calculators do.
  221. setvar membuff "\$$mem"
  222. update dir.calc 5 $membuff
  223.  
  224. xButton 90 108 20 15 O
  225. setvar membuff "\$$mem"
  226. AppVar calc.var $membuff
  227. update dir.calc 1 $calc.var
  228.  
  229. xButton 110 108 20 15 +
  230. setvar membuff "\$$mem"
  231. cli "rx 'say >env:$mem $calc.var + $membuff'"
  232. setvar membuff "\$$mem"
  233. update dir.calc 5 $membuff
  234.  
  235. xButton 130 108 20 15 -
  236. setvar membuff "\$$mem"
  237. cli "rx 'say >env:$mem $membuff - $calc.var'"
  238. setvar membuff "\$$mem"
  239. update dir.calc 5 $membuff
  240.  
  241.  
  242. ;***************************** Ticker Tape **********************************
  243.  
  244. ; Here we expand the window to include a listview for the ticker tape
  245. ; This is done on clicking of the Right Mouse Button
  246.  
  247. xOnRMB
  248. if $calcmode = SMALL
  249.    calcmode = BIG
  250.    changegad dir.calc 0 -1 -1 320 128 ""
  251.    setgad dir.calc 2 SHOW
  252. else
  253.    calcmode = SMALL
  254.    lvuse dir.calc 2
  255.    lvclear
  256.    changegad dir.calc 0 -1 -1 160 128 ""
  257.    setgad dir.calc 2 HIDE
  258. endif
  259. redraw dir.calc
  260.  
  261. ;---- This is the listview that will show the results
  262. ;     update main calc pannel according to lv line clicked
  263.  
  264. xListview 155 5 158 123 "" calc.lv "" 10 TXT
  265. gadid 2
  266. cutvar calc.lv copy char 3 calc.3    ; update display to line content
  267. if $calc.3 = '** '            ; clear line
  268.    calc.var = 0
  269. else
  270.    if $calc.3 = '=> '            ; a result
  271.       cutvar calc.lv cut char 3 ""
  272.       calc.var = $calc.lv
  273.    else
  274.       calc.var = $calc.lv        ; a calculation
  275.    endif
  276. endif
  277. update dir.calc 1 $calc.var
  278. if $calc.var = 0
  279.    calc.var = ''
  280. endif
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.